﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Tools;
using Tour.DAL;

namespace Tour.BLL
{
    /// <summary>
    /// Summary description for TblReservationDetail
    /// </summary>
    public class TblReservationDetailManagerBase
    {
        public TblReservationDetailManagerBase()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public void InsertUpdate(TblReservationDetailEntity item)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", item.Id));
            ls.Add(new SqlParameter("@TextId", item.TextId));
            ls.Add(new SqlParameter("@ReservationId", item.ReservationId));
            ls.Add(new SqlParameter("@TypeRoomId", item.TypeRoomId));
            ls.Add(new SqlParameter("@NumberAdults", item.NumberAdults));
            ls.Add(new SqlParameter("@NumberChild", item.NumberChild));
            ls.Add(new SqlParameter("@FromDate", item.FromDate));
            ls.Add(new SqlParameter("@ToDate", item.ToDate));
            ls.Add(new SqlParameter("@Promotion", item.Promotion));
            ls.Add(new SqlParameter("@Prepaid", item.Prepaid));
            ls.Add(new SqlParameter("@IsDelete", item.IsDelete));
            ls.Add(new SqlParameter("@CreatedBy", item.CreatedBy));
            ls.Add(new SqlParameter("@CreatedDate", item.CreatedDate));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_InsertUpdateTblReservationDetail", sqlparam);
        }
        public void InsertUpdate(int Id, string TextId, int ReservationId, int TypeRoomId, int NumberAdults, int NumberChild, System.DateTime FromDate, System.DateTime ToDate, int Promotion, decimal Prepaid, bool IsDelete, string CreatedBy, System.DateTime CreatedDate)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            ls.Add(new SqlParameter("@TextId", TextId));
            ls.Add(new SqlParameter("@ReservationId", ReservationId));
            ls.Add(new SqlParameter("@TypeRoomId", TypeRoomId));
            ls.Add(new SqlParameter("@NumberAdults", NumberAdults));
            ls.Add(new SqlParameter("@NumberChild", NumberChild));
            ls.Add(new SqlParameter("@FromDate", FromDate));
            ls.Add(new SqlParameter("@ToDate", ToDate));
            ls.Add(new SqlParameter("@Promotion", Promotion));
            ls.Add(new SqlParameter("@Prepaid", Prepaid));
            ls.Add(new SqlParameter("@IsDelete", IsDelete));
            ls.Add(new SqlParameter("@CreatedBy", CreatedBy));
            ls.Add(new SqlParameter("@CreatedDate", CreatedDate));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_InsertUpdateTblReservationDetail", sqlparam);
        }
        public string GetUniqueTextIdFromUnicodeText(string UnicodeText)
        {
            string strSql = @"  SELECT TextId FROM TblReservationDetail tn
                                WHERE tn.TextId=@TextId";
           string textId = WebUtility.GetUniqueTextIdFromUnicodeText(UnicodeText, "@TextId", strSql
               , SqlHelper.TourConnectString, 255);
           return textId;
        }
        public void Delete(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_DeleteTblReservationDetail", sqlparam);
        }
        public TblReservationDetailEntity GetTblReservationDetailEntity(DataRow dr)
        {
            TblReservationDetailEntity item = new TblReservationDetailEntity();            
            if (dr.Table.Columns.Contains("Id"))
                item.Id = dr["Id"].ToInt();              
            if (dr.Table.Columns.Contains("TextId"))
                item.TextId = dr["TextId"].ToString();              
            if (dr.Table.Columns.Contains("ReservationId"))
                item.ReservationId = dr["ReservationId"].ToInt();              
            if (dr.Table.Columns.Contains("TypeRoomId"))
                item.TypeRoomId = dr["TypeRoomId"].ToInt();              
            if (dr.Table.Columns.Contains("NumberAdults"))
                item.NumberAdults = dr["NumberAdults"].ToInt();              
            if (dr.Table.Columns.Contains("NumberChild"))
                item.NumberChild = dr["NumberChild"].ToInt();              
            if (dr.Table.Columns.Contains("FromDate"))
                item.FromDate = dr["FromDate"].ToDateTime();              
            if (dr.Table.Columns.Contains("ToDate"))
                item.ToDate = dr["ToDate"].ToDateTime();              
            if (dr.Table.Columns.Contains("Promotion"))
                item.Promotion = dr["Promotion"].ToInt();              
            if (dr.Table.Columns.Contains("Prepaid"))
                item.Prepaid = dr["Prepaid"].ToDecimal();              
            if (dr.Table.Columns.Contains("IsDelete"))
                item.IsDelete = dr["IsDelete"].ToBoolean();              
            if (dr.Table.Columns.Contains("CreatedBy"))
                item.CreatedBy = dr["CreatedBy"].ToString();              
            if (dr.Table.Columns.Contains("CreatedDate"))
                item.CreatedDate = dr["CreatedDate"].ToDateTime();              
            return item;
        }        
        public DataTable SelectOneRDT(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            return SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblReservationDetail", sqlparam);
        }
        public TblReservationDetailEntity SelectOne(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblReservationDetail", sqlparam);
            if(dt!=null && dt.Rows.Count>0)
                return GetTblReservationDetailEntity(dt.Rows[0]);
            return null;
        }
        public DataTable SelectAllRDT()
        {
            return SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblReservationDetailsAll", null);
        }
        public List<TblReservationDetailEntity> SelectAll()
        {
            List<TblReservationDetailEntity> lsresult= new List<TblReservationDetailEntity>();
            DataTable dt =  SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblReservationDetailsAll", null);
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetTblReservationDetailEntity(dt.Rows[i]));            
            return lsresult;
        }
    }
}

